#include ActiveRecord::Base
class BifinfoController < ApplicationController
	#def redirect_to_index(msg= nil)
		#flash[:notice] = msg if msg
		#redirect_to :action => :index
	#end

  layout "bifinfos"
  
  active_scaffold :infobif do |config|
  config.label = "BIF INFO FOR OUTPUT"
  config.action_links.add 'export_csv', :label => 'Export to Excel', :page => true
  config.action_links.add 'trunc_tbl', :label => 'Clear DataBase', :page => true
  end




  def trunc_tbl 
     #Infobif.delete_all
     #redirect_to :action => :index  
     ActiveRecord::Base.connection.execute("truncate table infobifs")
     redirect_to :action => :index
  end
  
  def export_csv
    # find_page is how the List module gets its data. see Actions::List#do_list.
    records = find_page().items
    return if records.size == 0

    # Note this code is very generic.  We could move this method and the
    # action_link configuration into the ApplicationController and reuse it
    # for all our models.
    data = ""
    cls = records[0].class
    data << cls.csv_header << "\r\n"
    records.each do |inst|
      data << inst.to_csv << "\r\n"
    end
    send_data data, :type => 'text/csv', :filename => cls.name.pluralize + '.csv'
  end
end
